<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:widget="http://www.netvibes.com/ns/"  >
  <head>

    <meta name="author" content="Netvibes" />
    <meta name="description" content="Netvibes Weather module" />

    <meta name="apiVersion" content="1.0" />
    <meta name="inline" content="true" />
    <meta name="autoRefresh" content="20" />
    <meta name="debugMode" content="false" />


    <link rel="stylesheet" type="text/css" href="http://www.netvibes.com/themes/uwa/style.css" />
    <script type="text/javascript" src="http://www.netvibes.com/js/UWA/load.js.php?env=Standalone"></script>

    <title>Weather</title>
    <link rel="icon" type="image/gif" href="http://www.netvibes.com/modules/weather/img/favicon.png" />

    <!-- Widget Preferences -->

    <widget:preferences>
      <preference name="townName" type="text" label="Town" defaultValue="" />
      <preference name="unit" type="list" label="Unit" defaultValue="0">

        <option value="0" label="Fahrenheit" />
        <option value="1" label="Celsius" />
      </preference>
      <preference name="showLocalTime" type="boolean" label="Show local time" defaultValue="0" />
      <preference name="town" type="hidden" defaultValue="" />
      <preference name="townCodeStore" type="hidden" defaultValue="" />

      <preference name="view" type="list" label="View" defaultValue="full" onchange="changeView">
        <option value="legacy" label="Compact" />

        <option value="full" label="Large" />
        <option value="large" label="Wide" />
      </preference>

      <preference name="view_full_collapsed" type="hidden" defaultValue="false" />

    </widget:preferences>

    <!-- Widget Styles -->

    <style type="text/css">
        .weather .content {
            color:white;
            font-size:1em;
        }
        .weather a {
            border:none!important;
        }
        .weather .loading {
            display:block;
            text-align:center;
            padding:12px 0 12px 0;
            color:#333;
        }

        .weather .placeholder {
            float:left;
        }

        .weather .top .infos {
            font-size:1.3em;
            line-height:1.3em;
            zoom:1;
        }


        .weather .top .weatherIcon {
            text-align:center;
        }

        .weather .bottom {
            clear:both;
        }

        .weather .separator, .weather .top .separator {
            background: no-repeat 100%;
        }
        .weather .bottom .infos{
        }

        .weather .footer {
            text-align:center;
            clear:both;
            height:1%;
        }

        .weather .footer a {
            color:#929292;
        }
        .weather .footer span {
            color:#595959;
            margin-left:10px;
            white-space:nowrap;
        }
        .weather .cityList {
            float:left;
            width:100%;
            background-position:0 119px;
            color:white;
            padding:5px;
        }

        .weather .cityList a {
            color:white;
        }

        .weather .content {
            clear:both;
        }
        .weather a.coloredLink {
            outline:none;
        }

        /* SKINS */

        /* white (default)*/
        .weather .cityList { background-color: #777; }
        .weather .content  { background-image:url(img/white/white_background.png?v=2); }
        .weather .separator { background-image:url(img/white/white_space_2.png); }
        .weather .bottom .separator { background-image:url(img/white/white_space_1.png); }
        .weather a.coloredLink, .weather .cityList a:hover { color:#a4a4a4; }
        .weather .footer span { color:#cacaca; }
        .weather .infos { color:#848484; }

        /* borderless */
        .weather .borderless .content, .weather .borderless .cityList  { background-image: none; }
        .weather .borderless .top .separator { background: none; }
        .weather .borderless .bottom .separator { background: none; }
        .weather .borderless a.coloredLink, .weather .borderless .cityList a:hover { color:black; }
        .weather .borderless .footer span { color:black; }
        .weather .borderless .infos, .weather .borderless .loading { color:black; }


        /* blue */
        .weather .blue .content, .weather .blue .cityList { background-image:url(img/blue/blue_background.png?v=2); }
        .weather .blue .separator { background-image:url(img/blue/blue_space_2.png); }
        .weather .blue .bottom .separator { background-image:url(img/blue/blue_space_1.png); }
        .weather .blue a.coloredLink, .weather .blue .cityList a:hover { color:#06afb5; }
        .weather .blue .footer span { color:#028185; }
        .weather .blue .infos, .weather .blue .loading { color:white; }

        /* red */
        .weather .red .content, .weather .red .cityList  { background-image:url(img/red/red_background.png?v=2); }
        .weather .red .separator { background-image:url(img/red/red_space_2.png); }
        .weather .red .bottom .separator { background-image:url(img/red/red_space_1.png); }
        .weather .red a.coloredLink, .weather .red .cityList a:hover { color:#c10202; }
        .weather .red .footer span { color:#880101; }
        .weather .red .infos, .weather .red .loading { color:white; }

        /* pink */
        .weather .orange .content, .weather .orange .cityList  { background-image:url(img/pink/pink_background.png?v=2); }
        .weather .orange .separator { background-image:url(img/pink/pink_space_2.png); }
        .weather .orange .bottom .separator { background-image:url(img/pink/pink_space_1.png); }
        .weather .orange a.coloredLink, .weather .orange .cityList a:hover { color:#bf1d6b; }
        .weather .orange .footer span { color:#7a0a3f; }
        .weather .orange .infos, .weather .orange .loading { color:white; }

        /* green */
        .weather .green .content, .weather .green .cityList  { background-image:url(img/green/green_background.png?v=2); }
        .weather .green .separator { background-image:url(img/green/green_space_2.png); }
        .weather .green .bottom .separator { background-image:url(img/green/green_space_1.png); }
        .weather .green a.coloredLink, .weather .green .cityList a:hover { color:#6c810d; }
        .weather .green .footer span { color:#424d0a; }
        .weather .green .infos,  .weather .green .loading { color:white; }

        /* grey */
        .weather .white .content, .weather .white .cityList  { background-image:url(img/grey/grey_background.png?v=2); }
        .weather .white .separator { background-image:url(img/grey/grey_space_2.png); }
        .weather .white .bottom .separator { background-image:url(img/grey/grey_space_1.png); }
        .weather .white a.coloredLink, .weather .white .cityList a:hover{ color:#929292; }
        .weather .white .footer span { color:#595959; }
        .weather .white .infos, .weather .white .loading { color:white; }

        /* orange */
        .weather .yellow .content, .weather .yellow .cityList { background-image:url(img/orange/orange_background.png?v=2); }
        .weather .yellow .separator { background-image:url(img/orange/orange_space_2.png); }
        .weather .yellow .bottom .separator { background-image:url(img/orange/orange_space_1.png); }
        .weather .yellow a.coloredLink, .weather .yellow .cityList a:hover{ color:#b35510; }
        .weather .yellow .footer span { color:#7b3706; }
        .weather .yellow .infos, .weather .yellow .loading { color:white; }

        .weather a:hover, .weather div, .weather span {
           zoom: 1;

        }

        /* 'legacy' version */
        .weather .legacy .placeholder{
            width:25%;
            *width:24%; /* IE hack */
        }


        .weather .legacy .infos {
            font-size:1.0em;
        }
            .weather .legacy .infos .days{
                padding-top:2px;
            }
        .weather .legacy .top {
            padding: 7px 0 0 0;
        }
        .weather .legacy .footer {
            padding: 11px 0 3px 0;
        }


        /* 'full' version */
        .weather .full .placeholder {
            width:33%;
        }

        .weather .full .top .icon {
            width:66%;
        }
        .weather .full .bottom .infos {
            font-size:1.0em;
        }

        .weather .full .top .infos {
            display:block;
        }
        .weather .full .bottom {
            padding-top:8px;
        }
        .weather .full .top .switchHeight {
            display:block;
            overflow:hidden;
        }
            .weather .full .top .switchHeight a {
                font-size:0.6em;
                text-decoration:underline;
                white-space:nowrap;
            }
        .weather .full .footer {
            padding: 6px 0 3px 0;
        }
        .weather .full .top .day {
            padding-top:5px;
        }
        .weather .full .collapsed {
            display:none;
        }

        /* 'large' version */
        .weather .large .top .infos {
            display:block;
        }
        .weather .large .top .day {
            padding-top:5px;
            overflow:hidden;
            width:100px;
        }
        .weather .large .footer {
            padding: 2px 0 3px 0;
        }
        .weather .large .top .text {
            padding-top:5px;
        }

        .weather .large .weatherIcon {
            text-align:left;
            font-size:1.0em;
            position:relative;
            _width:12px;
        }

        .weather .large .weatherIcon div ,
        .weather .large .weatherIcon span {
            display:inline;
        }
        .weather .large .weatherIcon .text {
            position:absolute;
            left:42px;
            top:3px;
        }
        .weather .large .bottom .placeholder {
            float:none;
        }
        .weather .large .bottom,
        .weather .large .top {
            clear:none;
            float:left;
        }
        .weather .large .top {
            width:50%;
            min-width:200px;
        }
        .weather .large .top .in {
            width:240px;
            min-width:200px;
            _width:250px;
            margin:auto auto;
        }
        .weather .large .bottom {
            width:50%;
            margin-top:7px;
            *width:40%; /* IE hack */
        }
        .weather .large .bottom .in{
            width:180px;
            margin:auto auto;
        }
        .weather .large .lineContener {
            height:83px;
            min-width:400px;
            white-space:nowrap;
            overflow:hidden;
        }

        .weather .footer {
            font-size: 0.9em;
        }
        .weather .top .day, .weather .bottom .day {
            font-weight:bold;
        }
        .weather .weatherIcon {
            text-align:center;
        }
            .weather .weatherIcon span {
                display:block;
            }

    </style>

    <!-- Widget Code -->

    <script type="text/javascript">

    // Netvibes' base URL (determining the proxy URL)
    var NV_MAIN_PATH = 'http://' + NV_HOST + '/';

    // Some predefined country code to save a query if not neccessary
    var Countries = {"afghanistan":"AFXX0003", "albania":"ALXX0002", "algeria":"AGXX0001", "angola":"AOXX0008",
     "argentina":"ARBA0009", "armenia":"AMXX0003", "australia":"ASXX0023", "austria":"AUXX0025",
     "azerbaijan":"AJXX0001", "bahamas":"BFXX0005", "bangladesh":"BGXX0003", "barbados":"BBXX0001",
     "belarus":"BOXX0005", "belgium":"BEXX0005", "belize":"BHXX0002", "benin":"BNXX0002", "bhutan":"BTXX0002",
     "bolivia":"BLXX0006", "bosnia and herzegovina":"BKXX0004", "botswana":"BCXX0001", "brazil":"BRXX0043",
     "bulgaria":"BUXX0005", "burkina faso":"UVXX0001", "burundi":"BYXX0001", "cambodia":"CBXX0001",
     "cameroon":"CMXX0008", "canada":"CAXX0343", "cape verde":"CVXX0002", "central african republic":"CTXX0001",
     "chad":"CDXX0003", "chile":"CIXX0020", "china":"CHXX0008", "colombia":"COXX0004", "comoros":"CNXX0003",
     "congo":"CGXX0005", "costa rica":"CSXX0009", "croatia":"HRXX0005", "cuba":"CUXX0003", "cyprus":"CYXX0005",
     "czech republic":"EZXX0012", "denmark":"DAXX0009", "djibouti":"DJXX0001", "dominica":"DOXX0002",
     "dominican republic":"DRXX0009", "ecuador":"ECXX0008", "egypt":"EGXX0004", "el salvador":"ESXX0001",
     "equatorial Guinea":"EKXX0003", "eritrea":"ERXX0001", "estonia":"ENXX0004", "ethiopia":"ETXX0001",
     "fiji":"FJXX0009", "finland":"FIXX0002", "france":"FRXX0076", "gabon":"GBXX0004",
     "gambia":"GAXX0001", "georgia":"GGXX0004", "germany":"GMXX0007",
     "ghana":"GHXX0001", "greece":"GRXX0004", "guatemala":"GTXX0002", "guinea":"GVXX0002",
     "guyana":"GYXX0001", "haiti":"HAXX0004", "honduras":"HOXX0008", "india":"INXX0096",
     "indonesia":"IDXX0022", "iran":"IRXX0018", "iraq":"IZXX0008",
     "ireland":"EIXX0014", "israel":"ISXX0010", "italy":"ITXX0067", "jamaica":"JMXX0002", "japan":"JAXX0085",
     "jordan":"JOXX0002", "kenya":"KEXX0009", "kiribati":"KRXX0002", "kuwait":"KUXX0003",
     "kyrgyzstan":"KGXX0001", "laos":"LAXX0001", "latvia":"LGXX0004", "lebanon":"LEXX0003",
     "lesotho":"LTXX0001", "liberia":"LIXX0002", "libya":"LYXX0009", "liechtenstein":"LSXX0002",
     "lithuania":"LHXX0005", "luxembourg":"LUXX0003", "madagascar":"MAXX0002", "malawi":"MIXX0002",
     "malaysia":"MYXX0008", "maldives":"MVXX0001", "mali":"MLXX0001", "malta":"MTXX0001", "mh":"USMH0002",
     "mauritania":"MRXX0004", "mexico":"MXDF0132", "fm":"USFM0004", "moldova":"MDXX0001",
     "morocco":"MOXX0007", "mozambique":"MZXX0003", "namibia":"WAXX0004", "nepal":"NPXX0002",
     "netherlands":"NLXX0002", "new zealand":"NZXX0049", "nicaragua":"NUXX0004", "niger":"NGXX0003",
     "nigeria":"NIXX0022", "norway":"NOXX0029", "oman":"MUXX0003", "pakistan":"PKXX0006", "panama":"PMXX0004",
     "papua new guinea":"PPXX0004", "paraguay":"PAXX0001", "peru":"PEXX0011", "philippines":"RPXX0017",
     "poland":"PLXX0028", "portugal":"POXX0016", "qatar":"QAXX0003", "romania":"ROXX0003",
     "russia":"RSXX0063", "rwanda":"RWXX0001", "saint lucia":"STXX0001", "san marino":"SMXX0001",
     "sao tome and principe":"TPXX0001", "saudi arabia":"SAXX0017", "senegal":"SGXX0001",
     "sierra leone":"SLXX0001", "singapore":"SNXX0006", "slovakia":"LOXX0001", "slovenia":"SIXX0002",
     "solomon islands":"BPXX0001", "somalia":"SOXX0002", "south africa":"SFXX0010", "spain":"SPXX0050",
     "sri lanka":"CEXX0001", "sudan":"SUXX0002", "suriname":"NSXX0002", "sweden":"SWXX0031",
     "switzerland":"SZXX0006", "syria":"SYXX0004", "tajikistan":"TIXX0001", "thailand":"THXX0002",
     "togo":"TOXX0001", "trinidad and tobago":"TDXX0002", "tunisia":"TSXX0010", "turkey":"TUXX0002",
     "tuvalu":"TVXX0001", "uganda":"UGXX0002", "ukraine":"UPXX0016", "united arab emirates":"AEXX0001",
     "united kingdom":"UKXX0085", "united states":"USDC0001", "uruguay":"UYXX0006", "uzbekistan":"UZXX0004",
     "venezuela":"VEXX0008", "vietnam":"VMXX0006", "yemen":"YMXX0005", "zambia":"ZAXX0004",
     "zimbabwe":"ZIXX0004"};

    // Module main settings
    var Settings = {
        proxyWeather: NV_MAIN_PATH + 'proxy/weatherProxy.php?town=',
        proxyLocation: NV_MAIN_PATH + 'modules/weather/location.php',
        proxyCitySearch: 'http://xoap.weather.com/search/search?where=',
        proxyWikiSearch: 'http://ws.geonames.org/wikipediaSearchJSON?maxRows=20&q=',
        partnerArgs: 'par=netvibes&site=netvibes&cm_ven=bd_select&cm_cat=netvibes&cm_pla=netvibes&cm_ite=CityPage',
        fallback: Countries.france
    }

    // "Weather" will be the container of our module's code
    var Weather = {};

    // "Weather.data" will store cached data about weather
    Weather.data = {};

    Weather.elements = {};

    // vars to be translated
    Weather.week_days = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
    Weather.months = [_("January"), _("February"), _("March"), _("April"), _("May"), _("June"), _("July"), _("August"), _("September"), _("October"), _("November"), _("December")];
    Weather.shortMonths = [_("Jan"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"), _("Jul"), _("Aug"), _("Sep"), _("Oct"), _("Nov"), _("Dec")];


    // This will periodically updates the title area of the module - works only with Netvibes.com inline mode
    Weather.showClock = function() {
        clockTimer = setInterval(function() {
           if (!widget || !Weather.data.dnam || widget.getValue('showLocalTime') == 'false') return;

           var time = widget.elements.title;
           if (time){
                var zone = Weather.data.zone;

                var d = new Date();
                var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
                var nd = (new Date(utc + (3600000 * zone)));
                var hh = nd.getHours();
                var mm = nd.getMinutes();
                var ss = nd.getSeconds();
                if (hh<10) hh = '0' + hh;
                if (mm<10) mm = '0' + mm;
                if (ss<10) ss = '0' + ss;

                time.setHTML(Weather.data.dnam + ' - <span style="font-weight:normal;">' + hh + ':' + mm + ':' + ss + '</span>');
           }
        }, 1000);
    };

    // A metadisplay function
    Weather.display = function(weather) {
        Weather.data = weather;
        if (typeof Weather.data.day != 'undefined') {
            Weather.displayContent();
        } else {
            widget.body.setHTML('<div align="center">' + _("This widget is currently unavailable") + '</div>');
        }
    }

    Weather.getTodayDisplayDate = function(){
        var nd = new Date();
        var monthStr = Weather.shortMonths[nd.getUTCMonth()];
        var day = nd.getDate();

        return day + ' ' + monthStr;
    },

    Weather.getTodayDisplayDay = function(){
        var nd = new Date();
        return Weather.week_days[nd.getDay()];
    }

    // Displays the weather, based on the cached data
    Weather.displayContent = function() {
        widget.setTitle(Weather.data.dnam);
        var viewType = widget.getValue('view') || 'full';

        var dom = Weather.views[viewType].getDOM(Weather.data);

        dom.inject(Weather.elements['content'].empty());

        widget.callback("onUpdateBody");
    }

    Weather.getLinkToProvider = function(){
        return 'http://www.weather.com/outlook/travel/businesstraveler/wxdetail/' + widget.getValue('town') + '?dayNum={0}&'+Settings.partnerArgs;
    }

    Weather.views = {};

    Weather.views.legacy  = {
        getDOM: function(datas){
            var isIE6 = (UWA.Client.Engine.ie && UWA.Client.Engine.version < 7);
            var days = datas.day;
            var now = datas.now;
            var html = '';

            var link = Weather.getLinkToProvider();

            html += '    <div class="line top">';
            for (var i = 0; i < 4; i++){
                var day = (i>0) ? days[i] : now;
                html += '    <div class="placeholder ' + ((i<3) ? 'separator' : '') + '">';
                html += '        <div class="weatherIcon">';
                html += '            <a href="' + link.format(i) + '"_blank">' + Weather.getImgCode(day.icon, _(day.text || ''), 'small') + '</a>';
                html += '            <span class="infos day">' + ((i>0) ? _(days[i].t) : Weather.getTodayDisplayDay()) + '</span>';
                html += '            <span class="infos temp">' + Weather.getTemp(day) + '</span>';
                html += '        </div>';
                html += '    </div>';
            }
            html += '    </div>';
            html += '    <div class="footer">'
            html += '        <a class="coloredLink" href="http://www.weather.com/outlook/travel/businesstraveler/tenday/' + widget.getValue('town') + '?' + Settings.partnerArgs + '" target="_blank">';
            html += '            ' + _("10 Day Weather Forecast");
            html += '        </a> ';
            html += '        <span class="powered">Powered by: The Weather Channel &reg;</span>';
            html += '    </div>';

            return widget.createElement('div', {'class' : 'legacy'}).setHTML(html);
        }
    }

    Weather.views.full  = {
        getCollapseBtText: function(){
            var collapsed = widget.getBool('view_full_collapsed');
            return ((collapsed) ? _('the next 3 days') : _('only show today'));
        },

        getDOM: function(datas){
            var html = '';
            var days = datas.day;
            var now = datas.now;
            var link = Weather.getLinkToProvider();

            html += '<div class="line top">';

            html += '    <div class="placeholder icon" >';
            html += '        <div class="weatherIcon" >';
            html += '            <a href="' + link.format(0) + '">' + Weather.getImgCode(now.icon, _(now.text || '')) + '</a>';
            html += '        </div>';
            html += '    </div>';
            html += '    <div class="placeholder">';
            html += '        <span class="infos day">' + Weather.getTodayDisplayDate() + '<br />' + Weather.getTodayDisplayDay() + '</span>';
            html += '        <span class="infos temp">' + Weather.getTemp(now) + '</span>';
            html += '        <span class="infos switchHeight"><a class="coloredLink" href="javascript:return false;">' + Weather.views.full.getCollapseBtText() + '</a></span>';
            html += '    </div>';
            html += '</div>';


            html += '<div class="line bottom">';
            for (var i = 1; i < 4; i++){
                html += '    <div class="placeholder ' + ((i<3) ? 'separator' : '') + '">';
                html += '        <div class="weatherIcon">';
                html += '            <a href="' + link.format(i) + '">' + Weather.getImgCode(days[i].icon, _(days[i].text || ''), 'small')+ "</a>";
                html += '            <span class="infos day">' + _(days[i].t) + '</span>';
                html += '            <span class="infos temp">' + Weather.getTemp(days[i]) + '</span>';
                html += '        </div>';
                html += '    </div>';
            }
            html += '</div>';
            html += '<div class="footer">'
            html += '    <a class="coloredLink" href="http://www.weather.com/outlook/travel/businesstraveler/tenday/' + widget.getValue('town') + '?' + Settings.partnerArgs + '" target="_blank">';
            html += '        ' + _("10 Day Weather Forecast");
            html += '    </a> ';
            html += '    <span class="powered">Powered by: The Weather Channel &reg;</span>';
            html += '</div>';
            var dom = widget.createElement('div', {'class' : 'full'}).setHTML(html);
            Weather.elements['collapsable'] = UWA.$element(dom.getElementsByClassName('bottom')[0]);
            Weather.elements['collapsable'].addClassName((widget.getBool('view_full_collapsed')) ? 'collapsed' : '');

            Weather.elements['switchBt'] = dom.getElementsByClassName('top')[0].getElementsByClassName('coloredLink')[0];
            Weather.elements['switchBt'].onclick = Weather.views.full.switchCollapse;

            return dom;
        },

        switchCollapse: function(){
            var collapsed = widget.getBool('view_full_collapsed');

            if (!collapsed){
                Weather.elements['collapsable'].addClassName('collapsed');
                widget.setValue('view_full_collapsed', true);
            } else {
                Weather.elements['collapsable'].removeClassName('collapsed');
                widget.setValue('view_full_collapsed', false);
            }

             Weather.elements['switchBt'].setHTML(Weather.views.full.getCollapseBtText());

            return false;
        }
    }

   Weather.views.large  = {

        getDOM: function(datas){
            var html = '';

            var days = datas.day;
            var now = datas.now;

            var link = Weather.getLinkToProvider();

            html += '<div class="lineContener"><div class="line top separator">';
            html += '    <div class="in">';
            html += '        <div class="placeholder icon">';
            html += '            <div class="weatherIcon">';
            html += '                <a href="' + link.format(0) + '"_blank">' + Weather.getImgCode(now.icon, _(now.text || '')) + '</a>'
            html += '            </div>';
            html += '        </div>';
            html += '        <div class="placeholder text">';
            html += '            <span class="infos day">' + Weather.getTodayDisplayDate() + '<br />' + Weather.getTodayDisplayDay() + '</span>';
            html += '            <span class="infos temp">' + Weather.getTemp(now) + '</span>';
            html += '        </div>';
            html += '    </div>';
            html += '</div>';


            html += '    <div class="line bottom">';
            html += '        <div class="in">';
            for (var i = 1; i < 4; i++){
                html += '    <div class="placeholder">';
                html += '        <div class="weatherIcon">';
                html += '            <a href="' + link.format(i) + '"_blank">' + Weather.getImgCode(days[i].icon, _(days[i].text || ''), 'tiny') + '</a>';
                html += '            <div class="text">';
                html += '                <span class="infos day">' + _(days[i].t) + '</span>';
                html += '                <span class="infos temp">' + Weather.getTemp(days[i]) + '</span>';
                html += '            </div>';
                html += '        </div>';
                html += '    </div>';
            }
            html += '    </div>';
            html += '</div></div>';

            html += '<div class="footer">'
            html += '    <a class="coloredLink" href="http://www.weather.com/outlook/travel/businesstraveler/tenday/' + widget.getValue('town') + '?' + Settings.partnerArgs + '" target="_blank">';
            html += '        ' + _("10 Day Weather Forecast");
            html += '    </a> ';
            html += '    <span class="powered">Powered by: The Weather Channel &reg;</span>';
            html += '</div>';

            var dom = widget.createElement('div', {'class' : 'large'}).setHTML(html);

            return dom;
        }
    }

    // Converts Fahrenheit to Celsius
    Weather.toCelsius = function(n) {
        if (isNaN(n)) return "N/A";
        var calc = Math.round((n-32)*5/9);
        return (isNaN(calc)) ? "N/A" : calc;
    }

    // Returns with a hi/lo tempreature string
    Weather.getTemp = function(node){
        var isCelcius = (widget.getValue('unit') == 1);
        var unit = (isCelcius) ? 'C' : 'F';
        var hi = node.hi;
        var low = node.low;
        var currentTemp = node.tmp;

        if (isCelcius) {
            hi = Weather.toCelsius(hi);
            low = Weather.toCelsius(low);
            currentTemp = Weather.toCelsius(currentTemp);
        }

        if (!node.tmp) {
            var result = low;
            if ('N/A' != hi) {
                result += "/" + hi + "\u00B0" + unit;
            } else {
                result += "\u00B0" + unit;
            }
        } else {
            var result = currentTemp + "\u00B0" + unit;
        }

        return result;
    };

    // Returns with some HTML code with an image (some PNG tricks for IE)
    Weather.getImgCode = function(filename, text, size) {
        if (filename=="N/A") filename = "NA";
        if (filename.length==1) filename = "0"+filename;
        if (text=="N/A") text = "";
        if (size == 'small'){
            filename = 'icon_M/' + filename;
            var size = ['65px', '40px'];
        } else if (size == 'big' || !size){
            filename = 'icon_L/' + filename;
            var size = ['129px', '80px'];
        } else if (size == 'tiny'){
            filename = 'icon_S/' + filename;
            var size = ['35px', '22px'];
        }

        if (UWA.Client.Engine.ie && UWA.Client.Engine.version < 7) {
            var c = '<div class="linkToProvider" style="zoom:1; margin-left:auto; margin-right:auto; height:' + size[1] + '; width:' + size[0] + '; cursor:pointer; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src=\''+NV_STATIC+'/modules/weather/img/'+filename+'.png?v=3\', sizingMethod=\'crop\');" title="' + text + '"></div>';
        } else {
            var c = '<div class="linkToProvider" ><img src="'+NV_STATIC+'/modules/weather/img/' + filename + '.png?v=3" title="' + text + '" alt="' + text + '" /></div>';
        }

        return c;
    };

    // Queries the weather data from our proxy
    Weather.getWeather = function() {
        var c = widget.body.getElementsByClassName('cityList');
        c[0].style.display = 'none';
        UWA.Data.getJson(Settings.proxyWeather+escape(widget.getValue('town')), Weather.display);
    };

    // Process the response from the getLocation() query
    Weather.locationResponder = function(value) {
        loc = JSON.decode(value);

        // by default, the unit will be Celsius
        widget.setValue('unit', 1);

        // if the city not found at all, let's do a fallback
        if (!loc || loc.error) {
            Weather.updateForLocation(Settings.fallback);
            return false;
        }

        // try to build or town string, or do a fallback
        town = '';
        try {
            countryName = loc.countryName.toLowerCase();
            if (cache[countryName]) {
                fallback = Countries[countryName];
            }

            if (loc.countryCode == "US") {
                town = loc.city + ", " + loc.region;
            } else if (loc.city != "") {
                town = loc.city + ", " + countryName;
            } else {
                Weather.updateForLocation(Settings.fallback);
            }
        } catch (e) {
            Weather.updateForLocation(Settings.fallback);
        }

        // if country is US, the unit will be Fahrenheit
        if (countryName && countryName == "united states"){
            widget.setValue('unit', 0);
        }

        // do a location search by Weather.com service to get their city code
        UWA.Data.getXml(Settings.proxyCitySearch + escape(town), Weather.locationSearchResponder);
    };


    // Process the response from Weather.com city search / code lookup service
    Weather.locationSearchResponder = function(xml) {
        var rootNode = xml.documentElement;
        var r = rootNode.getElementsByTagName("loc");
        var ln = r.length;
        if (ln==1 || r[0]) {
            Weather.updateForLocation(r[0].getAttribute("id"));
            return true;
        }
        Weather.updateForLocation(Settings.fallback);
    };

    // Save a good city code, and query weather data
    Weather.updateForLocation = function(townCode) {
        widget.setValue('town', townCode);
        Weather.getWeather();
    };

    // Get "real city name" based on the string from the user (using GeoIP)
    Weather.getLocation = function() {
        UWA.Data.getText(Settings.proxyLocation, Weather.locationResponder);
    };

    // The first step in searching a code for a city string
    Weather.searchCities = function(name) {

        var c = widget.body.getElementsByClassName('cityList');

        var resultDiv = c[0];
        resultDiv.innerHTML = _("Loading...");
        resultDiv.style.display = 'block';

        // Process the response from Weather.com city search / code lookup service
        function checkResult(xml) {

            var rootNode = xml.documentElement;
            var r = rootNode.getElementsByTagName("loc");
            var ln = r.length;

            // We have exactly one city, save and display it
            if (ln==1) {
                Weather.updateForLocation(r[0].getAttribute("id"));

            // We have no search results, do another search using wikipedia data
            } else if (ln==0) {
                UWA.Data.getJson(Settings.proxyWikiSearch + encodeURIComponent(name), getEnglishName);

            // We have more than one results, let the user choose
            } else {
                displayResultList(xml);
            }
        }

        // Get the English name from the wikipedia search response, and do a search at Weather.com again
        function getEnglishName(results) {
            results = results.geonames;
            var found = false;
            var cities = [];
            var bigestPopulation = 0;
            for (var i = 0; i < results.length; i++) {
                if (results[i].population > 0) {
                    cities.push({title: results[i].title, population: results[i].population});
                    found = true;
                }
            }
            for (i = 0; !found && i < results.length; i++) {
                if (results[i].feature == "" || results[i].feature == "city") {
                    cities.push({title: results[i].title, population: results[i].population});
                    found = true;
                }
            }
            for (i = 0; found && i < cities.length; i++) {
                if (cities[i].population >= bigestPopulation) {
                    name = cities[i].title;
                    bigestPopulation = cities[i].population;
                }
            }
            UWA.Data.getXml(Settings.proxyCitySearch+encodeURIComponent(name), displayResultList);
        }

        // Show a list of results if we have more than one city (or display "no info" or the city's weather)
        function displayResultList(xml) {
            var rootNode = xml.documentElement;
            var r = rootNode.getElementsByTagName("loc");
            var ln = r.length;
            if (ln==1) {
                Weather.updateForLocation(r[0].getAttribute("id"));
            } else if (ln==0) {
                resultDiv.innerHTML = '<span style="color:#900">'+_("No information for this town")+'</span>';
            } else {
                var span = widget.createElement("span").setHTML('<strong>' + _("Select your location:") + '</strong> ');
                for (var z=0; z<ln; z++) {
                    var a = widget.createElement("a", {'href' : 'javascript:;'});
                    a.onclick = function() {
                        Weather.updateForLocation(this.getAttribute("idTown"));
                        return false;
                    }
                    a.setAttribute("idTown", r[z].getAttribute("id"));
                    a.setHTML(r[z].firstChild.nodeValue);
                    a.inject(span);

                    if (z<ln-1){
                        var sep = widget.createElement("span").setHTML(' | ');
                        sep.inject(span);
                    }
                }
                resultDiv.empty();
                span.inject(resultDiv);
            }
            widget.callback("onUpdateBody");
        }

        // Check directly at Weather.com for the city code
        UWA.Data.getXml(Settings.proxyCitySearch + name, checkResult);
    };

    // UWA Search/Filter Handler
        widget.onSearch = function(query, type) {
                var c = widget.body.getElementsByClassName('content');
                c[0].innerHTML = '';
                var c = widget.body.getElementsByClassName('cityList');
                c[0].innerHTML = '';
                c[0].style.display = 'none';
        widget.callback("onUpdateBody");
                if (!type) { return; }
                if (!widget.getValue('townCodeStore')) {
                        widget.setValue('townCodeStore', widget.getValue('town'));
                }
                Weather.searchCities(query);
        }

    // UWA Search/Filter Reset Handler
        widget.onResetSearch = function() {
                var townCode;
                if (townCode = widget.getValue('townCodeStore')) {
                        widget.setValue('town', townCode);
                }
                Weather.getWeather();
        }

    // UWA Refresh Handler
    widget.onRefresh = function() {
        var town;
        var c = widget.body.getElementsByClassName('cityList'); c[0].style.display = 'none';
        if (town = widget.getValue('townName')) {
            widget.setValue('townName', '');
            Weather.searchCities(town);
        } else {
            Weather.getWeather();
        }
        if (widget.getValue('showLocalTime')=='true') {
            Weather.showClock();
        }
    }

    // Main code
    widget.onLoad = function() {

        var townCode;
        if (townCode = widget.getValue('townCodeStore')) {
            widget.setValue('town', townCode);
            widget.setValue('townCodeStore', '');
        }

        widget.setBody('<div class="main weather"><div class="cityList"></div><div class="content"><span class="loading">' + _("Loading...") + '</span></div></div>');

        widget.body.setStyle('padding', '0');
        Weather.elements['main'] = UWA.$element(widget.body.getElementsByClassName('main')[0]);
        Weather.elements['content'] = UWA.$element(widget.body.getElementsByClassName('content')[0]);

        var skin = widget.getValue('color') || '';
        Weather.elements['main'].addClassName(skin);



        if (widget.getValue('showLocalTime')=='true') {
            Weather.showClock();
        }
        if (town = widget.getValue('townName')) {
            widget.setBody('<div class="cityList"></div><div class="content"></div>');
            widget.setValue('townName', '');
            Weather.searchCities(town);
        } else {
            if (!widget.getValue('town')) {
                Weather.getLocation();
            } else {
                Weather.getWeather();
            }
        }
    };

    widget.onColorize = function(){
        var new_class = 'main';
        var col = widget.getValue('color');
        if (col) {
            new_class += ' ' + col;
        }
        Weather.elements['main'].className = new_class;
    };

    widget.changeView = function(){
        Weather.elements['content'].empty();
        Weather.displayContent();
    };

    </script>

  </head>
  <body>
    <p>Loading """""""""""""""""""...</p>
  </body>
</html>